package auto.app.controller;


import auto.app.controller.from.AutoGlobal.AutoGlobalAddFrom;
import auto.app.controller.from.AutoGlobal.AutoGlobalDeleteFrom;
import auto.app.controller.from.AutoGlobal.AutoGlobalPageFrom;
import auto.app.controller.from.AutoGlobal.AutoGlobalUpdateFrom;
import auto.app.controller.info.AutoGlobal.AutoGlobalDetailInfo;
import auto.app.controller.info.AutoGlobal.AutoGlobalPageInfo;
import auto.app.exetion.HibernateExetion;
import auto.app.exetion.MainExection;
import auto.app.model.AutoGlobal;
import auto.app.service.AutoGlobalService;
import auto.app.util.CommonUtil;
import auto.app.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2022-08-18
 */
@RestController
@RequestMapping("/autoGlobal")
@Api(value = "全局参数",tags = "全局参数")
@AllArgsConstructor
public class AutoGlobalController {
    AutoGlobalService autoGlobalService;

    @PostMapping(name = "新增全局参数")
    @ApiOperation(value = "新增全局参数",notes = "新增全局参数")
    public Result<Boolean> addAutoGlobal(@Valid @RequestBody AutoGlobalAddFrom autoGlobalAddFrom) throws MainExection {
        Boolean aBoolean = autoGlobalService.addAutoGlobal(autoGlobalAddFrom);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }

    @PutMapping(name = "修改全局参数")
    @ApiOperation(value = "修改全局参数",notes = "修改全局参数")
    public Result<Boolean> updateAutoGlobal(@Valid @RequestBody AutoGlobalUpdateFrom autoGlobalUpdateFrom) throws MainExection {
        Boolean aBoolean = autoGlobalService.updateAutoGlobal(autoGlobalUpdateFrom);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }
    @GetMapping(value = "/{globalId}",name = "全局参数查看详情")
    @ApiOperation(value = "查看详情",notes = "查看详情")
    public Result<AutoGlobalDetailInfo> autoGlobalDetail(@PathVariable String globalId) throws MainExection {
        AutoGlobalDetailInfo autoGlobalDetailInfo = autoGlobalService.autoGlobalDetail(globalId);
        return Result.getInstance(AutoGlobalDetailInfo.class).setData(autoGlobalDetailInfo);
    }
    @PostMapping(value = "/list",name = "全局参数页面列表")
    @ApiOperation(value = "全局参数页面列表",notes = "全局参数页面列表")
    public Result<AutoGlobalPageInfo> autoGlobalList(@RequestBody AutoGlobalPageFrom autoGlobalPageFrom) {
        AutoGlobalPageInfo autoGlobalPageInfo = autoGlobalService.autoGlobalList(autoGlobalPageFrom);
        return Result.getInstance(AutoGlobalPageInfo.class).setData(autoGlobalPageInfo);
    }

    @GetMapping(value = "/use/list",name = "用例页面显示全局参数")
    @ApiOperation(value = "用例页面显示全局参数",notes = "用例页面显示全局参数")
    public Result<List<AutoGlobal>> autoGlobalListCase() {
        List<AutoGlobal> autoGlobals = autoGlobalService.autoGlobalListCase();
        return Result.getInstanceList(AutoGlobal.class).setData(autoGlobals);
    }

    @DeleteMapping(name = "删除全局参数")
    @ApiOperation(value = "删除接口",notes = "删除接口")
    public Result<Boolean> deleteGlobalList(@RequestBody AutoGlobalDeleteFrom autoGlobalDeleteFrom) throws MainExection {
        Boolean aBoolean = autoGlobalService.deleteGlobalList(autoGlobalDeleteFrom);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }
}

